//
//  HomeViewModel.swift
//  Weibo项目
//
//  Created by vn on 16/7/23.
//  Copyright © 2016年 vn. All rights reserved.
//

import UIKit

class HomeViewModel: NSObject {

    
    //全局数组
     var homeDataArray:[StatusViewModel] = [StatusViewModel]()
    
    //获取网络数据
    func requestHomeData(success:(isSucc:Bool)->()){
        
       
        NetworkTools.sharedManagerTolls.getHomeDataInfo({ (response) -> () in
            
            guard let res = response?["statuses"] as?[[String: AnyObject]]else{
                
                success(isSucc: false)
                return
                
            }
            //定义一个临时数组
            var tempArray:[StatusViewModel] = [StatusViewModel]()
            
            for dic in res{
                
                //字典转模型
                let model = HomeVCModel(dict:dic)
                  //然后把模型赋值给viewModel的属性
                let viewModel = StatusViewModel(homeModel:model)
                
                tempArray.append(viewModel)
                
            }
            
            //给属性数组赋值
             self.homeDataArray = tempArray
            success(isSucc: true)
            
            }) { (error) -> () in
            
                
                print("请求错误",error)
                
        }
        
    }
    
}
